package com.example.library_room

import io.reactivex.SingleObserver
import io.reactivex.disposables.Disposable
import java.sql.SQLException

abstract class AppDataObserver<T> : SingleObserver<T> {
    override fun onSuccess(t: T) {
        success(t)
    }

    override fun onSubscribe(d: Disposable) {

    }

    override fun onError(e: Throwable) {
        if (e is SQLException){
            error("SQL exception")
        }else{
            error(e.message)
        }
    }

    /**
     * 错误/异常回调
     */
    protected abstract fun error(error: String?)

    /**
     * 成功回调
     */
    protected abstract fun success(result: T)
}